// 秒转换:时间
export function timeToText(time: any) {
  const a = Math.floor(time / 60), b = time % 60;

  return (a >= 10 ? a : ('0' + a)) + ':' + (b >= 10 ? b : ('0' + b))
}

// 当时时间
export function thisTime() {
  const date = new Date()

  return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`
}

// 传参obj
export function urlObj(obj: any) {
  let str = ''

  Object.keys(obj).forEach((key) => {
    str += (str === '' ? '' : '&') + `${key}=${obj[key]}`
  })

  return str
}


// 初始化数据
export function initData(data: any) {
  Object.keys(data).forEach(key => {
    switch (typeof data[key]) {
      case 'number': data[key] = 0; break;
      case 'string': data[key] = ''; break;
      case 'object': data[key] = {}; break;
      case 'boolean': data[key] = false; break;
      default: data[key] = null
    }
  })
}


// 日期
export function getDateText(date: any = new Date()) {
  const y = date.getFullYear()
  const m = date.getMonth() + 1
  const d = date.getDate()

  return `${y}-${m > 10 ? m : '0' + m}-${d > 10 ? d : '0' + d}`
}